export { createApp } from "vue";
import { type App } from "vue";
import "@icon-park/vue-next/styles/index.css";
import "./style.css";
import { install } from "@icon-park/vue-next/es/all";
import { useStateStore } from "./state"

const modules: any = import.meta.glob("./**/*vue", { eager: true });

function getComponentName(path: string) {
  return path
    .split("/")
    .map((part: any) => part.charAt(0).toUpperCase() + part.slice(1))
    .join("");
}

function prefix(name: string) {
  return `Umrp${name}`;
}


export default {
  install(app: App) {
    install(app);
    app.config.globalProperties.$state = function (key: string, value: any) {
      const stateStore = useStateStore()
      stateStore.state[key] = value
    }
    for (const key in modules) {
      const componentPath = key.replace(/\.\//, "").replace(".vue", "").replace("index", "");
      const componentName = prefix(getComponentName(componentPath));
      app.component(componentName, modules[key]?.default);
    }
  },
};
